package com.yuke.cloud.service.uac.controller.frontend;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.base.constant.GlobalConstant;
import com.yuke.cloud.common.base.dto.GroupInfoDto;
import com.yuke.cloud.common.base.dto.LoginAuthDto;
import com.yuke.cloud.common.base.enums.ErrorCodeEnum;
import com.yuke.cloud.common.core.annotation.LogAnnotation;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.HttpAesUtil;
import com.yuke.cloud.common.util.PublicUtil;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.api.uac.exceptions.UacBizException;
import com.yuke.cloud.service.uac.dto.*;
import com.yuke.cloud.service.uac.entity.AccRole;
import com.yuke.cloud.service.uac.entity.AccUser;
import com.yuke.cloud.service.uac.service.*;
import com.yuke.cloud.service.uac.utils.Md5Util;
import com.yuke.cloud.service.uac.vo.MenuVo;
import com.yuke.cloud.service.uac.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;

/**
* Created by wg on 2018/09/12.
*/
@Api(value = "WEB - AccUserController", tags = "处理AccUser相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/acc/user")
public class AccUserController extends BaseController {
    @Autowired
    private AccUserService accUserService;
    @Resource
    private AccUserRoleService accUserRoleService;
    @Resource
    private AccUserGroupService accUserGroupService;
    @Resource
    private AccEmployeeGroupService accEmployeeGroupService;
    @Resource
    private AccRoleService accRoleService;
    @Resource
    private AccMenuService accMenuService;
    @Resource
    private AccUserInfoService accUserInfoService;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    private Wrapper UpdateOrAddUser(AccUser accUser) {
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        accUserService.saveAccUser(accUser, loginAuthDto);
        return WrapMapper.ok(accUser);
    }

    @PostMapping
    @ApiOperation(httpMethod = "POST", value = "新增一条记录")
    public Wrapper add(@ApiParam(name = "accUser", value = "该数据记录的POJO") @RequestBody AccUser accUser) {
//        accUserService.save(accUser);
//        return WrapMapper.ok();
        return UpdateOrAddUser(accUser);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(httpMethod = "DELETE", value = "根据id删除一条记录")
    public Wrapper delete(@ApiParam(name = "id", value = "记录id") @PathVariable Long id) {
        accUserService.deleteById(id);
        return WrapMapper.ok();
    }

    @PutMapping
    @ApiOperation(httpMethod = "PUT", value = "修改一条记录")
    public Wrapper update(@ApiParam(name = "accUser", value = "需要修改的内容") @RequestBody AccUser accUser) {
//        accUserService.update(accUser);
//        return WrapMapper.ok();

        return UpdateOrAddUser(accUser);
    }

    @GetMapping("/{id}")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<AccUser> detail(@ApiParam(name = "id", value = "记录id") @PathVariable Long id) {
        AccUser accUser = accUserService.findById(id);
        return WrapMapper.ok(accUser);
    }

    @GetMapping
    @ApiOperation(httpMethod = "GET", value = "分页获取所有记录")
    public Wrapper<PageInfo<AccUser>> list(@ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                    @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {

        PageHelper.startPage(page, size);
        List<AccUser> list = accUserService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }

    /**
     * 根据登录用户名查询用户详细信息（连表查询）.
     *
     * @return the wrapper
     */
    @GetMapping(value = "/userInfo/{loginName}")
    @ApiOperation(httpMethod = "GET", value = "根据loginName查询用户详细信息")
    public Wrapper<UserInfoDto> getUserInfoByLoginName(@PathVariable String loginName) {
        logger.info("根据loginName查询用户详细信息");
        UserInfoDto userInfoDto = new UserInfoDto();
        AccUser accUser = accUserService.findByLoginName(loginName);

        UserGroupDto userGroupDto = new UserGroupDto();
        if (accUser.getIsEmployee()){
            userGroupDto = accEmployeeGroupService.selectEmployeeGroupInfoByUserId(accUser.getUserId());
        }else{
            userGroupDto = accUserGroupService.selectUserGroupInfoByUserId(accUser.getUserId());
        }
        List<UserRoleDto> roleList = accUserRoleService.selectUserRoleInfoByUserId(accUser.getUserId());

        BeanUtils.copyProperties(accUser, userInfoDto);
        if (PublicUtil.isNotEmpty(roleList)) {
            userInfoDto.setRoles(new HashSet<>(roleList));
        }
        userInfoDto.setGroupInfo(userGroupDto);

        // 用户详细信息
        AccUserInfoDto accUserInfoDto = accUserInfoService.selectUserInfoByUserId(accUser.getUserId());
        userInfoDto.setUserDetailInfo(accUserInfoDto);

        return WrapMapper.ok(userInfoDto);
    }

    /**
     * 查询当前登录用户详细信息（连表查询）.
     *
     * @return the wrapper
     */
    @GetMapping(value = "/loginUserInfo/current")
    @ApiOperation(httpMethod = "GET", value = "查询当前登录用户详细信息")
    public Wrapper<UserInfoDto> getLoginUserInfo() {

        LoginAuthDto loginUser = getLoginAuthDto();

        UserInfoDto userInfoDto = new UserInfoDto();
        AccUser accUser = accUserService.findByLoginName(loginUser.getLoginName());
        UserGroupDto userGroupDto = new UserGroupDto();

        if (accUser.getIsEmployee()){
            userGroupDto = accEmployeeGroupService.selectEmployeeGroupInfoByUserId(accUser.getUserId());
        }else{
            userGroupDto = accUserGroupService.selectUserGroupInfoByUserId(accUser.getUserId());
        }

        List<UserRoleDto> roleList = accUserRoleService.selectUserRoleInfoByUserId(accUser.getUserId());

        BeanUtils.copyProperties(accUser, userInfoDto);
        if (PublicUtil.isNotEmpty(roleList)) {
            userInfoDto.setRoles(new HashSet<>(roleList));
        }
        userInfoDto.setGroupInfo(userGroupDto);

       //todo 20191116 获取group信息
        GroupInfoDto groupInfoDto = new GroupInfoDto();
        groupInfoDto.setGroupId(userGroupDto.getGroupId());
        groupInfoDto.setGroupName(userGroupDto.getGroupName());
        groupInfoDto.setLevel(userGroupDto.getLevel());
        groupInfoDto.setParentId(userGroupDto.getParentId());
        redisTemplate.opsForValue().set(GlobalConstant.Sys.ROLE_DEPARTMENT_ADMIN+accUser.getUserId(),groupInfoDto);

        //end todo
        // 用户详细信息
        AccUserInfoDto accUserInfoDto = accUserInfoService.selectUserInfoByUserId(accUser.getUserId());
        userInfoDto.setUserDetailInfo(accUserInfoDto);

        return WrapMapper.ok(userInfoDto);
    }

    /**
     * 查询用户列表.
     *
     * @param accUser the acc user
     *
     * @return the wrapper
     */
    @PostMapping(value = "/queryListWithPage")
    @ApiOperation(httpMethod = "POST", value = "查询用户列表")
    public Wrapper<PageInfo> queryUserListWithPage(@ApiParam(name = "accUser", value = "用户查询条件") @RequestBody AccUser accUser) {
        logger.info("查询用户列表uacUser={}", accUser);
        //获得groupId
        Long groupId = getGroupInfoDto().getGroupId();
        accUser.setGroupId(groupId);
        PageInfo pageInfo = accUserService.queryUserListWithPage(accUser);
        return WrapMapper.ok(pageInfo);
    }

    /**
     * 根据Id修改用户状态.
     *
     * @param modifyUserStatusDto the modify user status dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/modifyUserStatusById")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "根据Id修改用户状态")
    public Wrapper<Integer> modifyUserStatusById(@ApiParam(name = "modifyUserStatusDto", value = "用户禁用/启用Dto") @RequestBody ModifyUserStatusDto modifyUserStatusDto) {
        logger.info(" 根据Id修改用户状态 modifyUserStatusDto={}", modifyUserStatusDto);
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        AccUser accUser = new AccUser();
        accUser.setUserId(modifyUserStatusDto.getUserId());
        accUser.setIsEnable(modifyUserStatusDto.getIsEnable());

        int result = accUserService.modifyUserStatusById(accUser, loginAuthDto);
        return handleResult(result);
    }

    /**
     * 校验登录名唯一性.
     *
     * @param checkLoginNameDto the check login name dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/checkLoginName")
    @ApiOperation(httpMethod = "POST", value = "校验登录名唯一性")
    public Wrapper<Boolean> checkLoginName(@ApiParam(name = "loginName", value = "登录名") @RequestBody CheckLoginNameDto checkLoginNameDto) {
        logger.info("校验登录名唯一性 checkLoginNameDto={}", checkLoginNameDto);

        Long id = checkLoginNameDto.getUserId();
        String loginName = checkLoginNameDto.getLoginName();

        Example example = new Example(AccUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("loginName", loginName);
        if (id != null) {
            criteria.andNotEqualTo("userId", id);
        }

        int result = accUserService.selectCountByExample(example);
        return WrapMapper.ok(result < 1);
    }

    /**
     * 校验email唯一性.
     *
     * @param checkEmailDto the check email dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/checkEmail")
    @ApiOperation(httpMethod = "POST", value = "校验email唯一性")
    public Wrapper<Boolean> checkEmail(@RequestBody CheckEmailDto checkEmailDto) {
        logger.info("校验邮箱唯一性 checkEmailDto={}", checkEmailDto);

        Long id = checkEmailDto.getUserId();
        String email = checkEmailDto.getEmail();

        Example example = new Example(AccUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("email", email);
        if (id != null) {
            criteria.andNotEqualTo("userId", id);
        }

        int result = accUserService.selectCountByExample(example);
        return WrapMapper.ok(result < 1);
    }

    /**
     * 校验用户电话号码唯一性.
     *
     * @param checkUserPhoneDto the check user phone dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/checkUserPhone")
    @ApiOperation(httpMethod = "POST", value = "校验用户电话号码唯一性")
    public Wrapper<Boolean> checkUserPhone(@ApiParam(name = "checkUserPhoneDto", value = "校验用户电话号码唯一性Dto") @RequestBody CheckUserPhoneDto checkUserPhoneDto) {
        logger.info(" 校验用户电话号码唯一性 checkUserPhoneDto={}", checkUserPhoneDto);
        Long id = checkUserPhoneDto.getUserId();
        String mobileNo = checkUserPhoneDto.getMobile();
        Example example = new Example(AccUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mobile", mobileNo);

        if (id != null) {
            criteria.andNotEqualTo("userId", id);
        }

        int result = accUserService.selectCountByExample(example);
        return WrapMapper.ok(result < 1);
    }

    /**
     * 校验新密码是否与原始密码相同.
     *
     * @param checkNewPasswordDto 修改密码实体
     *
     * @return the wrapper
     */
    @PostMapping(value = "/checkNewPassword")
    @ApiOperation(httpMethod = "POST", value = "校验新密码是否与原始密码相同")
    public Wrapper<Boolean> checkNewPassword(@ApiParam(name = "checkNewPasswordDto", value = "校验新密码是否与原始密码相同Dto") @RequestBody CheckNewPasswordDto checkNewPasswordDto) {
        logger.info(" 校验新密码是否与原始密码相同 checkNewPasswordDto={}", checkNewPasswordDto);
        String loginName = checkNewPasswordDto.getLoginName();
        String newPassword = checkNewPasswordDto.getNewPassword();
        AccUser accUser = new AccUser();
        accUser.setLoginName(loginName);
        int result = 0;
        AccUser user = accUserService.findByLoginName(loginName);
        if (user == null) {
            logger.error("找不到用户. loginName={}", loginName);
        } else {
            accUser.setUserPassword(Md5Util.encrypt(newPassword));
            result = accUserService.selectCount(accUser);
        }
        return WrapMapper.ok(result < 1);
    }

    /**
     * 根据用户Id重置密码.
     *
     * @param userId the user id
     *
     * @return the wrapper
     */
    @LogAnnotation
    @PutMapping(value = "/resetLoginPwd/{userId}")
    @ApiOperation(httpMethod = "PUT", value = "根据用户Id重置密码")
    public Wrapper<AccUser> resetLoginPwd(@ApiParam(name = "userId", value = "用户ID") @PathVariable Long userId) {
        logger.info("resetLoginPwd - 根据用户Id重置密码. userId={}", userId);
        accUserService.resetLoginPwd(userId, getLoginAuthDto());
        return WrapMapper.ok();
    }

    /**
     * 根据userId查询用户详细信息（连表查询）.
     *
     * @return the wrapper
     */
    @GetMapping(value = "/queryUserInfo/{userId}")
    @ApiOperation(httpMethod = "GET", value = "根据userId查询用户详细信息")
    public Wrapper<UserVo> queryUserInfo(@PathVariable Long userId) {
        logger.info("根据userId查询用户详细信息");
        UserVo userVo = new UserVo();
//        AccUser accUser = accUserService.findByLoginName(loginName);
        AccUser accUser = accUserService.findUserInfoByUserId(userId);
        List<AccRole> roleList = accRoleService.findAllRoleInfoByUserId(accUser.getUserId());
        List<MenuVo> authTree = accMenuService.getOwnMenuListByUserId(accUser.getUserId(), null);
        BeanUtils.copyProperties(accUser, userVo);
        if (PublicUtil.isNotEmpty(roleList)) {
            userVo.setRoles(new HashSet<>(roleList));
        }
        userVo.setAuthTree(authTree);
        return WrapMapper.ok(userVo);
    }

    private Wrapper<Integer> setPwd(UserModifyPwdDto userModifyPwdDto) {
        logger.info("==》vue用户修改密码, userModifyPwdDto={}", userModifyPwdDto);

        logger.info("旧密码 oldPassword = {}", userModifyPwdDto.getOldPassword());
        logger.info("新密码 newPassword = {}", userModifyPwdDto.getNewPassword());
        logger.info("登录名 loginName = {}", userModifyPwdDto.getLoginName());

        LoginAuthDto loginAuthDto = getLoginAuthDto();

        int result = accUserService.userModifyPwd(userModifyPwdDto, loginAuthDto);
        return handleResult(result);
    }

    /**
     * 用户修改密码
     *
     * @param userModifyPwdDto the user modify pwd dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/modifyUserPwd")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "用户修改密码")
    public Wrapper<Integer> modifyUserPwd(@ApiParam(name = "userModifyPwdDto", value = "用户修改密码Dto") @RequestBody UserModifyPwdDto userModifyPwdDto) {
        return setPwd(userModifyPwdDto);
    }

    /**
     * 用户在APP上修改密码
     *
     * @param userModifyPwdDto the user modify pwd dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/modifyPwdPhone")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "用户修改密码")
    public Wrapper<Integer> modifyPwd(@ApiParam(name = "userModifyPwdDto", value = "用户修改密码Dto") @RequestBody UserModifyPwdDto userModifyPwdDto) {
        return setPwd(userModifyPwdDto);
    }

    /**
     * 用户在APP上修改支付密码
     *
     * @param userModifyPwdDto the user modify pwd dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/modifyPayPwd")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "用户修改支付密码")
    public Wrapper<Integer> modifyPayPwd(@ApiParam(name = "userModifyPwdDto", value = "用户修改密码Dto") @RequestBody UserModifyPwdDto userModifyPwdDto) {
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        int result = accUserService.userModifyPayPwd(userModifyPwdDto, loginAuthDto);
        return handleResult(result);
    }

    /**
     * 用户修改电话号码
     *
     * @param modifyUserMobile the user modify mobileNo dto
     *
     * @return the wrapper
     */
    @PostMapping(value = "/modifyMobileNo")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "用户修改手机号码")
    public Wrapper<Integer> modifyMobile(@ApiParam(name = "modifyUserMobile", value = "用户修改手机号码Dto") @RequestBody ModifyUserMobile modifyUserMobile) {

        LoginAuthDto loginAuthDto = getLoginAuthDto();

        int result = accUserService.userModifyMobileNo(modifyUserMobile, loginAuthDto);
        if (result == -1) {
            return WrapMapper.error("手机号已存在");
        } else {
            return handleResult(result);
        }
    }

    /**
     * 修改昵称
     *
     * @param userId the user modify
     * @param nickName
     *
     * @return the wrapper
     */
    @GetMapping(value = "/modifyNickName")
    @LogAnnotation
    @ApiOperation(httpMethod = "GET", value = "用户修改手机号码")
    public Wrapper<Integer> modifyNickName(@ApiParam(name = "userId", value = "用户ID") @RequestParam Long userId,
                                            @ApiParam(name = "nickName", value = "nickName") @RequestParam String nickName) {
        if (userId == null || nickName == null){
            return WrapMapper.error("参数错误，更新失败！");
        }
        AccUser accUser = new AccUser();
        accUser.setUserId(userId);
        accUser.setNickname(nickName);
        int result = accUserService.update(accUser);
        if (result == -1) {
            return WrapMapper.error("更新失败！");
        } else {
            return handleResult(result);
        }
    }

    @PostMapping(value = "/modifyHeadImgUri")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "修改一条记录")
    public Wrapper modifyHeadImgUri(@ApiParam(name = "accUser", value = "需要修改的内容") @RequestBody AccUser accUser) {
        if (accUser.getUserId() == null || accUser.getHeadImgUri() == null){
            return WrapMapper.error("参数不能为null");
        }
        accUserService.update(accUser);
        return WrapMapper.ok();

    }
    /**
     * 通过手机号、手机验证码进行身份确认
     */
    @PostMapping(value = "/verifyByMobile/{userId}")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "通过手机号、手机验证码进行身份确认")
    public Wrapper<Integer> verifyUserByMobile(@ApiParam(name = "userId", value = "用户ID") @PathVariable Long userId,
                                               @ApiParam(name = "smsCode", value = "短信验证码") @RequestParam String smsCode,
                                               @ApiParam(name = "mobile", value = "手机号") @RequestParam String mobile) {

        Example example = new Example(AccUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId).andEqualTo("mobile", mobile);

        int result = accUserService.selectCountByExample(example);

        if (result == 1) {
            return WrapMapper.ok();
        } else {
            return WrapMapper.error("用户不存在或信息不匹配");
        }
    }

    @GetMapping(value = "/getUserByShop/{shopId}")
    @ApiOperation(httpMethod = "GET", value = "分页获取所有记录")
    public Wrapper<PageInfo<AccUser>> GetUserListByShop(@ApiParam(name = "shopId", value = "用户ID") @PathVariable Long shopId,
                                                        @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                        @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size,
                                                        @ApiParam(name = "loginName", value = "登录名") @RequestParam(required = false) String loginName,
                                                        @ApiParam(name = "userName", value = "用户名") @RequestParam(required = false) String userName,
                                                        @ApiParam(name = "mobile", value = "手机号") @RequestParam(required = false) String mobile) {
        PageHelper.startPage(page, size);
        List<AccUser> list = accUserService.GetUserListByShop(shopId, loginName, userName, mobile);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }

    @GetMapping("/getBalance/{id}")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<Integer> getBalance(@ApiParam(name = "id", value = "记录id") @PathVariable Long id) {
        AccUser accUser = accUserService.findById(id);
        if (accUser != null && accUser.getAmountBalance() != null){
            String aBalance = HttpAesUtil.decode(accUser.getAmountBalance());
            Integer balance = 0;
            if (aBalance != "" && aBalance.length()>0){
                balance = Integer.valueOf(aBalance);
            }
            return WrapMapper.ok(balance);
        }
       return WrapMapper.error("获取数据错误，检查传入数据是否错误！");
    }

    /**
     * 验证支付密码
     */
    @PostMapping(value = "/verifyByPayPwd")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "通过手机号、手机验证码进行身份确认")
    public Wrapper<Integer> verifyByPayPwd(@ApiParam(name = "jsonObject", value = "用户ID") @RequestBody JSONObject jsonObject) {

        if (PublicUtil.isEmpty(jsonObject) || PublicUtil.isEmpty(jsonObject.get("userId")) || PublicUtil.isEmpty(jsonObject.get("payPassword"))){
            throw new UacBizException(ErrorCodeEnum.GL99990100);
        }
        Long userId = Long.parseLong(jsonObject.get("userId").toString());

        String payPassword = jsonObject.get("payPassword").toString().replaceAll(" ", "");
        System.out.println(payPassword);
        AccUser accUser = new AccUser();
        accUser.setUserId(userId);
        AccUser user = accUserService.selectOne(accUser);
        int result = 0;
        if (user == null) {
            logger.error("找不到用户. userId={}", userId);
        } else if(user.getPwdErrorCount() > 3){
            logger.error("连续错误超过3次！");
        }else {
            if (Md5Util.matches(payPassword,user.getPayPassword())){
                result = 1;
            }
        }
        if (result == 1) {
            if (user.getPwdErrorCount() > 0){
                user.setPwdErrorCount((short)0);
                user.setPwdErrorTime(new Date());
                accUserService.update(user);
            }

            return WrapMapper.ok(result);
        } else {
            user.setPwdErrorCount((short)(user.getPwdErrorCount()+1));
            user.setPwdErrorTime(new Date());
            accUserService.update(user);
            return WrapMapper.error("密码错误！");
        }
    }

    @PostMapping(value = "/addPayPwd")
    @ApiOperation(httpMethod = "POST", value = "设置初始支付密码")
    public int  test21( @RequestBody JSONObject jsonObject){
        if (PublicUtil.isEmpty(jsonObject) || PublicUtil.isEmpty(jsonObject.get("userId")) && PublicUtil.isEmpty(jsonObject.get("mobile"))){
            throw new UacBizException(ErrorCodeEnum.GL99990100);
        }
        List<AccUser> accUserList = new ArrayList<>();
        if (jsonObject.get("userId").toString().equals("all") && jsonObject.get("mobile").toString().equals("all")){
            accUserList = accUserService.selectAll();
        }else{
            Long userId = Long.parseLong(jsonObject.get("userId").toString());
            System.out.println(userId);
            AccUser accUser = new AccUser();
            accUser.setUserId(userId);

            accUserList = accUserService.select(accUser);
        }

       if (accUserList != null && accUserList.size()>0){
           for(AccUser accUser : accUserList){
               String mobileNo = accUser.getMobile();
               if (mobileNo != null && mobileNo.length() == 11){

                   accUser.setPayPassword(Md5Util.encrypt(mobileNo.substring(5,11)));
                   return accUserService.update(accUser);
               }
           }
       }else{
           throw new UacBizException(ErrorCodeEnum.GL9999404);
       }
        return 0;
    }

    @PostMapping("/getUserListByName")
    @ApiOperation(httpMethod = "POST", value = "分页获取所有记录")
    public Wrapper<PageInfo<AccUser>> getlist(@ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                           @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size,
                                              @ApiParam(name = "accUser", value = "每分页返回的记录", defaultValue = "0") @RequestBody AccUser accUser   ) {

        PageHelper.startPage(page, size);
        Example example = new Example(AccUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("userName","%"+ accUser.getUserName() +"%");
        List<AccUser> list = accUserService.selectByExample(example);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }
}
